﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;

namespace SilverlightParser.Web.Backend
{
    class Remoter
    {
        static Remoter remoter;
        public static Remoter GetRemoter()
        {

            if (remoter == null)
            {
                remoter = new Remoter();
                remoter.Initialize();
            }
            return remoter;
        }

        void Initialize()
        {
            //string configfile = System.Windows.Forms.Application.StartupPath + "\\Client.exe.config";
            //System.Runtime.Remoting.RemotingConfiguration.Configure(configfile, false);
            HttpChannel channel = new HttpChannel();
            ChannelServices.RegisterChannel(channel, false);

            // Registers the remote class. (This could be done with a
            // configuration file instead of a direct call.)

            Type type = Type.GetType("Semantics.Base.RemotableMentor, Semantics.Base");
            RemotingConfiguration.RegisterWellKnownClientType(
                type,
                "tcp://157.55.20.229:8989/RemotableMentor");
            Type type2 = typeof(Semantics.Distribute.RemotableDialogue);// Type.GetType("Semantics.Distribute.RemotableDialogue, Semantics.Base");
            RemotingConfiguration.RegisterWellKnownClientType(
                type2,
                "tcp://157.55.20.229:8989/RemotableDialogue");
        }

        Semantics.Base.RemotableMentor type;
        public Semantics.Base.RemotableMentor GetRemotableType()
        {
            if (type == null)
                type = new Semantics.Base.RemotableMentor();
            return type;
        }
        Semantics.Distribute.RemotableDialogue dialogue;
        public Semantics.Distribute.RemotableDialogue GetRemotableDialogue(string contact)
        {
            if (dialogue == null)
                dialogue = new Semantics.Distribute.RemotableDialogue();
            return dialogue;
        }
    }
}
